package voja.android.sqldroid;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class SettingsActivity extends Activity {
	
	public static final String PREFS_NAME = "UserSettings";
	public SharedPreferences prefs;
	public SharedPreferences.Editor prefsEditor;
	
	public Button btnSave;
	public EditText txtDestination;
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings);
        
        prefs = getSharedPreferences(PREFS_NAME, 0);
        prefsEditor = prefs.edit();
        loadPrefs();
        
        btnSave = (Button)findViewById(R.id.btnSave);
        btnSave.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				SettingsActivity sa = (SettingsActivity)v.getContext();
				sa.prefsEditor.putString("destination", sa.txtDestination.getText().toString());
				sa.prefsEditor.commit();
				finish();
			}
		});
    }
	
	public void loadPrefs(){
		txtDestination = (EditText)findViewById(R.id.txtDestination);
		txtDestination.setText(prefs.getString("destination", "/sdcard"));
	}
}
